package com.atguigu.controller;

import com.atguigu.entity.HouseUser;
import com.atguigu.service.HouseUserService;
import com.sun.org.apache.xpath.internal.operations.Mod;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
@RequestMapping("/houseUser")
public class HouseUserController {
    @DubboReference
    private HouseUserService houseUserService;


    /*/houseUser/create?houseId=[[${house.id}]]*/
    @RequestMapping("/create")
    public String create(@RequestParam("houseId") Long houseId, ModelMap modelMap){
        modelMap.addAttribute("houseId",houseId);
        return "houseUser/create";
    }

    @RequestMapping("/save")
    public String save(HouseUser houseUser){
    houseUserService.index(houseUser);
    return "common/successPage";
    }
    /* opt.openWin('/houseUser/edit/' + id,'修改房东',630,430);*/
    @RequestMapping("/edit/{id}")
    public String edit(@PathVariable("id")int id,ModelMap modelMap){
        HouseUser houseUser = houseUserService.getById(id);
        modelMap.addAttribute("houseUser",houseUser);
        return "houseUser/edit";
    }
    @RequestMapping("update")
    public String update(HouseUser houseUser){
        houseUserService.update(houseUser);
        return "common/successPage";
    }
    /*  opt.confirm('/houseUser/delete/[[${house.id}]]/'+id);*/
    @RequestMapping("delete/{houseId}/{id}")
    public String deleted(@PathVariable Long houseId,@PathVariable int id){
        houseUserService.delete(id);
        return "redirect:/house/"+houseId;
    }
}
